//
//  WYMessageDetailController.m
//  Boss
//
//  Created by admin on 2018/7/4.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYMessageDetailController.h"
#import "WYMessageModel.h"
@interface WYMessageDetailController ()<UIWebViewDelegate>
@property (strong, nonatomic) IBOutlet UILabel *topNameLabel;
@property (strong, nonatomic) IBOutlet UILabel *timeLabel;
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topHeight;
@property (nonatomic,strong)WYMessageModel *messageModel;

@end

@implementation WYMessageDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self loadData];
}
-(void)loadData
{
    WEAKSELF
    [WYHttpServer getMessageDetailWithMsgId:self.msgID SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            [weakSelf upDateUI];
            weakSelf.messageModel = [WYMessageModel getMessageDetailModelFromJson:response[@"result"]];
            [weakSelf upDateUI];
        }else{
            [weakSelf toast:errorMessage];
        }
        
        
    }];
    
    
}
-(void)upDateUI
{
    self.topNameLabel.text = self.messageModel.title;
    self.timeLabel.text = [NSString compareTimeWithBossTime:self.messageModel.releaseTime];
    NSString *htmlString = [NSString stringWithFormat:@"<style>img{display:block;width:100%%;}</style><meta content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;\" name=\"viewport\" />%@",self.messageModel.content];
    
    NSLog(@"%@",htmlString);
    
    
    [self.webView loadHTMLString:htmlString baseURL:nil];
    
    
}

-(void)setupUI
{
    self.navigationItem.title = @"消息详情";
    self.topHeight.constant = self.navHeight +15;
    self.view.backgroundColor = [UIColor hexStringToColor:@"#ffffff" alpha:1.0];
    self.webView.backgroundColor = [UIColor hexStringToColor:@"#f7f7f7" alpha:1.0];
    self.webView.delegate = self;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
//    [webView stringByEvaluatingJavaScriptFromString:@"var Img=document.getElementByTagName('img');for(var i=0;i<img.length;i++){Img[i].style.width='100%'}"];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
